package com.huike.web.controller.report;


import com.huike.clues.domain.vo.IndexStatisticsVo;
import com.huike.report.domain.vo.StatisticVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.web.bind.annotation.*;

import com.huike.common.core.domain.AjaxResult;
import com.huike.report.service.IReportService;

import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/index")
public class IndexController {

    @Autowired
    private IReportService reportService;


    /**
     * 首页--基础数据统计
     *
     * @param beginCreateTime
     * @param endCreateTime
     * @return
     */
    @GetMapping("/getBaseInfo")
    public AjaxResult getBaseInfo(@RequestParam("beginCreateTime") String beginCreateTime,
                                  @RequestParam("endCreateTime") String endCreateTime) {
        return AjaxResult.success(reportService.getBaseInfo(beginCreateTime, endCreateTime));
    }

    /**
     * 获取今日简报
     *
     * @return
     */
    @GetMapping("/getTodayInfo")
    public AjaxResult getTodayInfo() {
        return AjaxResult.success(reportService.getTodayInfo());
    }

    /**
     * 商机转化龙虎榜
     *
     * @param request
     * @return
     */
    @GetMapping("/businessChangeStatistics")
    public AjaxResult businessChangeStatistics(IndexStatisticsVo request) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        request.setBeginCreateTime(request.getBeginCreateTime() + " 00:00:00");
        request.setEndCreateTime(request.getEndCreateTime() + " 23:59:59");
        List<Map<String, Object>> list = reportService.businessChangeStatisticsForIndex(request);
        return AjaxResult.success(list);
    }

    /**
     * 线索转化龙虎榜
     *
     * @param request
     * @return
     */
    @GetMapping("/salesStatistic")
    public AjaxResult salesStatistic(IndexStatisticsVo request) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        request.setBeginCreateTime(request.getBeginCreateTime() + " 00:00:00");
        request.setEndCreateTime(request.getEndCreateTime() + " 23:59:59");
        List<StatisticVo> list = reportService.salesStatisticForIndex(request);
        return AjaxResult.success(list);
    }

    @GetMapping("/getTodoInfo")
    public AjaxResult todoInfo(@RequestParam("beginCreateTime") String beginCreateTime,
                               @RequestParam("endCreateTime") String endCreateTime) {
        return AjaxResult.success(reportService.todoInfo(beginCreateTime, endCreateTime));
    }
}